import 'dart:convert';
import 'package:chewie/chewie.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
// import 'package:panda/base/SignType.dart';
import '../../util/SignUtil.dart';
import 'package:video_player/video_player.dart';
import '../../base/Constant.dart';
import '../../http/Api.dart';
import '../../http/HttpUtil.dart';
import '../../entity/article_list_entity.dart';
class SCVideoPage extends StatefulWidget {
  HomeListDataData model;
  SCVideoPage({Key key, @required this.model}) : super(key: key);

  _SCVideoPageState createState() => _SCVideoPageState();
}

class _SCVideoPageState extends State<SCVideoPage> {
  String content = "";
  String title = "";
  String pubtime = "";
  String desc = "";
  String href;
  ChewieController chewieController;
  VideoPlayerController videoPlayerController;
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    getDetail();
  }

  @override
  void dispose() {
    if (videoPlayerController != null) {
      videoPlayerController.dispose();
      chewieController.dispose();
    }

    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      child: new Scaffold(
        appBar: AppBar(
          title: Text(
            title,
            style: TextStyle(color: Colors.black, fontSize: ScreenUtil.getInstance().setSp(BIG_FONT_SIZE))
          ),
          backgroundColor: Colors.white,
          elevation: 1.0,
          brightness: Brightness.light,
          iconTheme: IconThemeData(color: Colors.black87),
        ),
        body: new SingleChildScrollView(
          child: new Container(
            color: Colors.white,
            child: new Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                chewieController != null
                    ? Container(
                        height: ScreenUtil.getInstance().setHeight(DP_350),
                        child: Chewie(
                          controller: chewieController,
                        ))
                    : Container(),
                Padding(
                  padding: EdgeInsets.fromLTRB(15, 15, 15, 0),
                  child: Text(
                    title,
                    style: TextStyle(
                        color: Colors.black,
                        fontSize: 18,
                        fontWeight: FontWeight.bold),
                  ),
                ),
                Padding(
                  padding: EdgeInsets.fromLTRB(15, 5, 0, 0),
                  child: Text(
                    desc,
                    style: TextStyle(
                      color: Colors.black,
                      fontSize: 14,
                    ),
                  ),
                ),
                Container(
                  color: Colors.white,
                  padding: EdgeInsets.fromLTRB(15, 0, 15, 0),
                  child: Html(
                      data: content == null ? "" : content,
                      defaultTextStyle: TextStyle(
                          fontSize: ScreenUtil.getInstance()
                              .setSp(NORMAL_FONT_SIZE))),
                )
              ],
            ),
          ),
        ),
      ),
    );
  }

  getDetail() async {
    // Map map = new Map();
    // map['article_id'] = widget.article_id;
    // map['sign_type'] =createSignType(Api.URL_ARTICLE_MSG);
    // Response<String> response =
    //     await HttpUtil().post(Api.URL_ARTICLE_MSG, data: getSign(map));
    // Map userMap = json.decode(response.data);
    // print(userMap);
    // if (userMap['code'] == 1 && mounted) {
      setState(() {
        // print(userMap['data']['articleMsg']['content']
        //     .toString()
        //     .replaceAll("src=\"", "src=\"" + Api.BaseUrl));
        content = widget.model.content
            .toString()
            .replaceAll("src=\"", "src=\"" + Api.BaseUrl);
        title = widget.model.title;
        desc = '';
        href = widget.model.video_url;
        if (href != null && href != "") {
          videoPlayerController = VideoPlayerController.network(href);
          chewieController = ChewieController(
            videoPlayerController: videoPlayerController,
            aspectRatio: 3 / 2,
            autoPlay: true,
            looping: true,
          );
        }
      });
    // }
  }
}
